﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AmiEmuLib.Configuration.EventBindingConfig;
using System.Xml;
using TomanuExtensions;
using TomanuExtensions.Utils;

namespace AmiEmuLib.AmigaConfiguration.JoyportsConfig
{
    /// <summary>
    /// Joyport configuration.
    /// </summary>
    public abstract class Joyport : XmlBase
    {
        /// <summary>
        /// Set only when we map host keyboard to game port device.
        /// </summary>
        public EventsBinding EventsBinding;

        /// <summary>
        /// Amiga device connected to joyport.
        /// </summary>
        public ConnectedDeviceType ConnectedDevice;

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="a_reader"></param>
        public Joyport(XmlReader a_reader)
            : base(a_reader)
        {
        }

        protected override void ReadXml(XmlReader a_reader)
        {
            ConnectedDevice = a_reader.GetAttributeEnum<ConnectedDeviceType>("ConnectedDevice");

            a_reader.ReadStartElement(GetType().Name);
            EventsBinding = AmigaConfig.ResolveBindings(new EventsBinding(a_reader, false));
            
            a_reader.ReadEndElement();
        }

        public override void WriteXml(XmlWriter a_writer)
        {
            a_writer.WriteStartElement(GetType().Name);

            a_writer.WriteAttribute("ConnectedDevice", ConnectedDevice);
            EventsBinding.WriteXml(a_writer);

            a_writer.WriteEndElement();
        }
    }
}
